package com.longqinuo.mycarservice.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.entity.CarBrand;

import java.util.List;

/**
 * 自定义快递电话列表适配器
 * Created by zxw on 2016/6/8.
 */
public class CarBrandAdapter extends BaseAdapter {
    private Context context;
    private List<CarBrand> mList;
    public CarBrandAdapter(Context context,List<CarBrand> list) {
        // TODO Auto-generated constructor stub
        this.context = context;
        this.mList = list;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return mList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.selected_car_type_item, null);

            holder.tvPinYin = (TextView) convertView.findViewById(R.id.tv_pinyin_selected_brand);
            holder.ivLogo = (ImageView) convertView.findViewById(R.id.iv_logo_selected_brand);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv_name_selected_brand);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mList.get(position).getName().equals("")) {
            holder.tvPinYin.setVisibility(View.VISIBLE);
            holder.ivLogo.setVisibility(View.GONE);
            holder.tvName.setVisibility(View.GONE);

        } else {
            holder.tvPinYin.setVisibility(View.GONE);
            holder.ivLogo.setVisibility(View.VISIBLE);
            holder.tvName.setVisibility(View.VISIBLE);
        }
        holder.tvPinYin.setText((mList.get(position).getPinYinName().charAt(0)+"").toUpperCase());
        holder.ivLogo.setImageResource(mList.get(position).getLogo());
        holder.tvName.setText(mList.get(position).getName());

        return convertView;
    }

    class ViewHolder {
        TextView tvPinYin;
        ImageView ivLogo;
        TextView tvName;

    }
}
